package com.esunny.db.hbase;

import java.util.HashMap;
import java.util.Random;

public class InsertAction extends Action {

    private Random                  random = new Random();
    private HashMap<String, String> hm     = null;

    @Override
    public void before() {
        int keynum = random.nextInt(this.keySpace);
        key = "user" + keynum;
        hm = new HashMap<String, String>();
        for (int i = 1; i < this.fieldSize; i++) {
            hm.put("field" + i, StringUtils.getRandomString(this.valueSize));
        }
    }

    @Override
    public int execute() {
        return cli.insert(this.tableName, key, hm);
    }

    @Override
    public void after() {
        hm = null;
    }
}
